package com.lsl.musicplayer.util;

import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.provider.MediaStore;

import java.util.ArrayList;
import java.util.List;

public class AudioScanner {

    public static List<String> scanAudioFiles(Context context) {
        List<String> audioFiles = new ArrayList<>();
        ContentResolver contentResolver = context.getContentResolver();
        Cursor mAudioCursor = contentResolver.query(
                MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                null,
                null,
                null,
                null
        );
        for (int i = 0; i < mAudioCursor.getCount(); i++) {
            mAudioCursor.moveToNext();
            String path = mAudioCursor.getString(mAudioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
            audioFiles.add(path);
        }
        mAudioCursor.close();
        return audioFiles;
    }
}
